package com.jeasonzhao.report.model;

import java.util.Date;

public class ReportAgentSummary implements java.io.Serializable
{
	private static final long serialVersionUID=1L;
    public static final String PREPARE = "PREPARE";
    public static final String LOAD_FROM_CACHE = "LOAD_FROM_CACHE";
    public static final String LOAD_FROM_DATASOURCE = "LOAD_FROM_DATASOURCE";
    public static final String SUB_TOTAL = "SUB_TOTAL";
    public static final String ROTATE = "ROTATE";
    public static final String EXPRESSION_EVLUATOR = "EXPRESSION_EVLUATOR";
    public static final String DICT_PROCESS = "DICT_PROCESS";
    public static final String CELL_FORMAT = "CELL_FORMAT";
    public static final String SAVE_TO_CACHE = "SAVE_TO_CACHE";
    public static final String APPEND_OPERATION = "APPEND_OPERATION";

    private Date m_startTime = new Date();
    private Date m_endTime = new Date();
    private long m_startMilliseconds = System.currentTimeMillis();
    private String m_strReportId = null;
    private java.util.Hashtable<String,Long> m_allTimeSnippet = new java.util.Hashtable<String,Long>();
    public ReportAgentSummary(Report report)
    {
        this.m_strReportId = null == report ? null : report.getReportId();
    }

    public void start()
    {
        this.m_startTime = new Date();
        m_startMilliseconds = System.currentTimeMillis();
        m_allTimeSnippet.clear();
    }

    public Date getStartTime()
    {
        return m_startTime;
    }

    public Date getEndTime()
    {
        return m_endTime;
    }

    public void end()
    {
        this.m_endTime = new Date();
    }

    @SuppressWarnings("unused")
    private long step(String key)
    {
        long time = System.currentTimeMillis() - this.m_startMilliseconds;
        if(m_startMilliseconds < 0)
        {
            m_startMilliseconds = System.currentTimeMillis();
            time = 0;
        }
        if(null != key && key.trim().length() > 0)
        {
            key = key.toLowerCase().trim();
            this.m_allTimeSnippet.put(key,Long.valueOf(time));
        }
        return 0;
    }

    public long getTotal()
    {
        long time = 0;
        if(null != m_allTimeSnippet)
        {
            java.util.Iterator<Long> it = m_allTimeSnippet.values().iterator();
            while(it.hasNext())
            {
                time += it.next().longValue();
            }
        }
        return time;
    }

    public String getReportId()
    {
        return m_strReportId;
    }

    public void setReportId(String reportId)
    {
        this.m_strReportId = reportId;
    }

}
